﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IHISCETeim.BLL;
using IHISCETeim.Library;
using IHISCETeim.Model;
using System.Data;

namespace IHISCETeim.Web.MachineSys.UserModel
{
    public partial class UReturnVisitReport : PageBase
    {
        protected override Permission[] PowerKey
        {
            get
            {
                return new Permission[] { Permission.查看 };
            }
        }
        protected override string DWZRef
        {
            get
            {
                return "UReturnVisitReport";
            }
        }
        #region 属性 (查询条件)

        protected string VisitType
        {
            get
            {
                return GetRequestValue<string>("VisitType", "8");
            }
        }
        protected string CreateDateFrom
        {
            get
            {
                return GetRequestValue<string>("CreateDateFrom", DateTime.Now.ToString("yyyy-MM-01"));


            }
        }

        protected string CreateDateTo
        {
            get
            {
                string temp = GetRequestValue<string>("CreateDateTo", "");
                if (string.IsNullOrEmpty(CreateDateFrom))
                    return "";
                if (string.IsNullOrEmpty(temp))
                {
                    temp = Convert.ToDateTime(CreateDateFrom).AddMonths(1).AddDays(-1).ToString("yyyy-MM-dd");
                }

                return temp;
            }
        }

       

        #endregion
        protected   DataTable sumdt = new DataTable();
        protected void Page_Load(object sender, EventArgs e)
        {
            DataTableCollection dts = UReturnVisitController.GetReport(CreateDateFrom, CreateDateTo, VisitType);
            this.rpMenu.DataSource = dts[0];
            this.rpMenu.DataBind();
           // sumdt = dts[1];
            AddLog(Permission.查看);
        }
        protected object GetSUMDT(string FiledName)
        {
            if (sumdt.Rows.Count <= 0)
                return 0;
            return sumdt.Rows[0][FiledName];
        }

        protected object GetPer(string 被除数, string 除数)
        {
            decimal x被除数 = Convert.ToDecimal(GetSUMDT(被除数));
            decimal x除数 = Convert.ToDecimal(GetSUMDT(除数));
            if (x除数 == 0)
                return 0;
            return ((x被除数 / x除数)*100).ToString("f0");
        }
        protected object GetPer(object 被除数, object 除数)
        {
            decimal x被除数 = Convert.ToDecimal(被除数);
            decimal x除数 = Convert.ToDecimal(除数);
            if (x除数 == 0)
                return 0;
            return ((x被除数 / x除数)*100).ToString("f0")+"%";
        }

        protected string GetGuide(object Guide, object VisitNum)
        {
            if (VisitNum == DBNull.Value)
                return "";
            if (Guide == DBNull.Value)
                return "";

            if (Convert.ToDecimal(VisitNum) == 0m)
                return "";
            if (Convert.ToDecimal(Guide) == 0m)
                return "";
             decimal xx = Convert.ToDecimal(Guide) / Convert.ToDecimal(VisitNum);

            if (xx >= 4)
                return "非常满意";
            if (xx >= 3)
                return "满意";
            if (xx >= 2)
                return "一般";
            if (xx >= 1)
                return "不满意";

            return "恶劣";
        }

        protected string GetPJJG(object PJJG, object VisitNum)
        {
            if (VisitNum == DBNull.Value)
                return "";
            if (PJJG == DBNull.Value)
                return "";

            if (Convert.ToDecimal(VisitNum) == 0m)
                return "";
            if (Convert.ToDecimal(PJJG) == 0m)
                return "";
            decimal xx = Convert.ToDecimal(PJJG) / Convert.ToDecimal(VisitNum);

            if (xx >= 4)
                return "不能接受";
            if (xx >= 3)
                return "价格偏贵";
            if (xx >= 2)
                return "能接受";
            if (xx >= 1)
                return "价格一般";

            return "价格一般";
        }
    }
}